load("@fbcode//fboss/lib/phy:sai_xphy.bzl", "all_sai_xphy_libs")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:thrift_library.bzl", "thrift_library")
load("//fboss/lib/phy:sai_phy_management.bzl", "all_sai_phy_management_libs")

oncall("fboss_agent_push")

thrift_library(
    name = "phy",
    go_thrift_namespaces = {
        "phy.thrift": "neteng.fboss.phy",
    },
    languages = [
        "cpp2",
        "py-deprecated",
        "py3-deprecated",
        "go",
        "py-deprecated-asyncio",
        "rust",
        "python",
    ],
    py3_namespace = "neteng.fboss.phy",
    py_asyncio_base_module = "neteng.fboss.asyncio",
    py_base_module = "neteng.fboss",
    thrift_cpp2_options = "json,reflection",
    thrift_py_options = "json",
    thrift_rust_options = [
        "deprecated_default_enum_min_i32",
        "serde",
    ],
    thrift_srcs = {"phy.thrift": ["FbossCommonPhyCtrl"]},
    deps = [
        ":prbs",
        "//common/fb303/if:fb303",
        "//fboss/agent:switch_config",
        "//fboss/agent/if:fboss",
        "//fboss/lib/if:fboss_io_stats",
        "//fboss/qsfp_service/if:transceiver",
        "//thrift/annotation:thrift",
    ],
)

thrift_library(
    name = "prbs",
    go_thrift_namespaces = {
        "prbs.thrift": "neteng.fboss.prbs",
    },
    languages = [
        "cpp2",
        "py-deprecated",
        "py3-deprecated",
        "go",
        "py-deprecated-asyncio",
        "rust",
        "python",
    ],
    py3_namespace = "neteng.fboss.prbs",
    py_asyncio_base_module = "neteng.fboss.asyncio",
    py_base_module = "neteng.fboss",
    thrift_cpp2_options = "json,reflection",
    thrift_py_options = "json",
    thrift_rust_options = [
        "deprecated_default_enum_min_i32",
        "serde",
    ],
    thrift_srcs = {"prbs.thrift": []},
)

thrift_library(
    name = "link",
    go_thrift_namespaces = {
        "link.thrift": "neteng.fboss.link",
    },
    languages = [
        "cpp2",
        "py-deprecated",
        "py3-deprecated",
        "go",
        "py-deprecated-asyncio",
        "rust",
        "python",
    ],
    py3_namespace = "neteng.fboss.link",
    py_asyncio_base_module = "neteng.fboss.asyncio",
    py_base_module = "neteng.fboss",
    thrift_cpp2_options = "json,reflection",
    thrift_py_options = "json",
    thrift_rust_options = [
        "deprecated_default_enum_min_i32",
        "serde",
    ],
    thrift_srcs = {"link.thrift": []},
)

cpp_library(
    name = "external_phy",
    srcs = [
        "ExternalPhy.cpp",
        "ExternalPhyPortStatsUtils.cpp",
    ],
    headers = [
        "ExternalPhy.h",
        "ExternalPhyPortStatsUtils.h",
        "NullPortStats.h",
    ],
    exported_deps = [
        ":phy-cpp2-types",
        "//common/stats:monotonic_counter",
        "//fb303:service_data",
        "//fboss/agent:fboss-error",
        "//fboss/agent:fboss-types",
        "//fboss/agent:platform_config-cpp2-types",
        "//fboss/agent/if:ctrl-cpp2-services",
        "//fboss/lib:alert_logger",
        "//fboss/lib:io_stats_recorder",
        "//fboss/mdio:mdio",
        "//folly:range",
        "//folly/json:dynamic",
        "//folly/logging:logging",
        "//thrift/lib/cpp/util:enum_utils",
        "//thrift/lib/cpp2/protocol:protocol",
    ],
)

cpp_library(
    name = "phy_management_base",
    srcs = [
        "PhyManager.cpp",
    ],
    headers = [
        "PhyManager.h",
    ],
    exported_deps = [
        ":external_phy",
        ":phy-cpp2-types",
        "//fb303:thread_cached_service_data",
        "//fboss/agent:fboss-error",
        "//fboss/agent:fboss-types",
        "//fboss/agent:phy_snapshot_lib",
        "//fboss/agent:switch_config-cpp2-types",
        "//fboss/agent/hw:hardware_stats-cpp2-types",
        "//fboss/agent/if:ctrl-cpp2-types",
        "//fboss/agent/platforms/common:platform_mapping",
        "//fboss/lib/config:fboss_config_utils",
        "//fboss/lib/link_snapshots:async_filewriter_factory",
        "//fboss/mdio:mdio",
        "//fboss/mka_service/if:mka_structs-cpp2-types",
        "//folly:synchronized",
        "//folly/futures:core",
        "//folly/logging:logging",
        "//thrift/lib/cpp/util:enum_utils",
    ],
)

cpp_library(
    name = "phy-management",
    srcs = [
        "facebook/bcm/BcmExternalPhyPortStats.cpp",
        "facebook/bcm/fuji/FujiPhyManager.cpp",
        "facebook/bcm/minipack/MinipackPhyManager.cpp",
        "facebook/credo/yamp/YampPhyManager.cpp",
        "facebook/credo/yamp/YampPortStats.cpp",
    ],
    headers = [
        "facebook/bcm/BcmExternalPhyPortStats.h",
        "facebook/bcm/fuji/FujiPhyManager.h",
        "facebook/bcm/minipack/MinipackPhyManager.h",
        "facebook/credo/yamp/YampPhyManager.h",
        "facebook/credo/yamp/YampPortStats.h",
    ],
    exported_deps = [
        ":external_phy",
        ":phy_management_base",
        "//fb303:service_data",
        "//fboss/agent:fboss-error",
        "//fboss/agent:fboss-types",
        "//fboss/agent/if:ctrl-cpp2-services",
        "//fboss/lib/fpga:minipack_container",
        "//fboss/lib/fpga/facebook/fuji:fuji_container",
        "//fboss/lib/fpga/facebook/yamp:yamp_fpga",
        "//fboss/lib/phy/facebook/bcm:bcm_external_phys",
        "//fboss/lib/phy/facebook/credo:credo",
        "//fboss/mdio:facebook_fpga_mdio",
        "//folly:conv",
        "//folly/logging:logging",
    ],
)

cpp_library(
    name = "phy_utils",
    srcs = [
        "PhyUtils.cpp",
    ],
    headers = [
        "PhyUtils.h",
    ],
    exported_deps = [
        ":phy-cpp2-types",
        "//fboss/agent:switch_config-cpp2-types",
    ],
)

all_sai_xphy_libs()

all_sai_phy_management_libs()
